//package cn.bonoon.kernel.util;
//
//import java.awt.image.BufferedImage;
//import java.io.InputStream;
//import java.io.OutputStream;
//import java.util.Hashtable;
//
//import javax.imageio.ImageIO;
//
//import com.google.zxing.BarcodeFormat;
//import com.google.zxing.BinaryBitmap;
//import com.google.zxing.DecodeHintType;
//import com.google.zxing.EncodeHintType;
//import com.google.zxing.LuminanceSource;
//import com.google.zxing.MultiFormatReader;
//import com.google.zxing.MultiFormatWriter;
//import com.google.zxing.Result;
//import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
//import com.google.zxing.client.j2se.MatrixToImageWriter;
//import com.google.zxing.common.BitMatrix;
//import com.google.zxing.common.HybridBinarizer;
//import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
//
///**
// * 二维码的处理对象
// * 
// * @author jackson
// * 
// */
//public final class MatrixCodeHelper extends BaseCode {
//	private ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.M;
//	private String characterSet = "GBK";
//
//	private MatrixCodeHelper() {
//		super(BarcodeFormat.QR_CODE, 300, 300);
//	}
//
//	public final static MatrixCodeHelper getHelper() {
//		return new MatrixCodeHelper();
//	}
//
//	public void encode(String contents, int width, int height,
//			OutputStream output) {
//		Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
//		// 指定纠错等级
//		hints.put(EncodeHintType.ERROR_CORRECTION, errorCorrectionLevel);
//		// 指定编码格式
//		hints.put(EncodeHintType.CHARACTER_SET, characterSet);
//		try {
//			BitMatrix bitMatrix = new MultiFormatWriter().encode(contents,
//					barcodeFormat, Math.max(minWidth, width),
//					Math.max(minHeight, height), hints);
//
//			MatrixToImageWriter.writeToStream(bitMatrix, formatName, output);
//
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
//
//	@Override
//	public String decode(InputStream input) {
//		BufferedImage image = null;
//		Result result = null;
//		try {
//			image = ImageIO.read(input);
//			if (image == null) {
//				throw new NullPointerException("二维码不存在!");
//			}
//			LuminanceSource source = new BufferedImageLuminanceSource(image);
//			BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
//
//			Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
//			hints.put(DecodeHintType.CHARACTER_SET, characterSet);
//
//			result = new MultiFormatReader().decode(bitmap, hints);
//			return result.getText();
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return null;
//	}
//
//	public final ErrorCorrectionLevel getErrorCorrectionLevel() {
//		return errorCorrectionLevel;
//	}
//
//	public final void setErrorCorrectionLevel(
//			ErrorCorrectionLevel errorCorrectionLevel) {
//		this.errorCorrectionLevel = errorCorrectionLevel;
//	}
//
//	public final String getCharacterSet() {
//		return characterSet;
//	}
//
//	public final void setCharacterSet(String characterSet) {
//		this.characterSet = characterSet;
//	}
//}
